package com.king.controller;

import cn.hutool.core.map.MapUtil;
import com.king.common.lang.Consts;
import com.king.common.lang.Result;
import com.king.im.vo.IMUser;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/chat")
public class ChatController extends BaseController {

    @GetMapping("/getMineAndGroupInfo")
    public Result getMineAndGroupInfo(){
        Map<String,Object> group = new HashMap<>();//默认群
        group.put("name","社区群聊");
        group.put("type","group");
        group.put("avatar","http://tp1.sinaimg.cn/5619439268/180/40030060651/1");
        group.put("id", Consts.IM_DEFAULT_GROUP_ID);
        group.put("members", 0);

        IMUser mine = chatService.getCurrentUser();

        return Result.success(MapUtil.builder()
                .put("group",group)
                .put("mine",mine)
                .map());
    }

    /**
     * 获取群聊历史记录
     * @return
     */
    @GetMapping("/getGroupHistoryMsg")
    public Result getGroupHistoryMsg(){
        List<Object> groupHistoryMsg = chatService.getGroupHistoryMsg(20);
        return Result.success(groupHistoryMsg);
    }
}
